# 获取svg字体信息
def svg_character(name_class_list, y_text_dict):
    # 拿到这个类名对应的字体的高度
    character_list = []
    for name_class in name_class_list:
        try:
            y = back_dict[name_class][1]
            # print(f'y:{y}')
            # 拿到这个类名对应的字体的x轴
            x = back_dict[name_class][0]
        except:
            print('error')

        # print(f'x:{x}')
        # 找对应的行数
        # 找对应的行数
        for index in y_text_dict.keys():
            # 第一个比y大的行数
            # print(index)
            if int(index) > int(y):
                # 计算x的位置, 14为字体的大小
                position = int(int(x) / 14)
                # print(position)
                # 从index这一行获取这个字体信息
                find_it = y_text_dict[index][position]
                # print(y_text_dict[index])
                # print(find_it, end="->")
                character_list.append(find_it)
                # 找到后跳出
                break
    # print(character_list)
    return character_list


# 正则匹配类名、x坐标、y坐标
# background_name_list = re.findall(r'\.(.*?){background:-(.*?).0px -(.*?)\.0px;}', text1)
# print(f'background_name_list: {background_name_list}')


# 映射文本获取
def mapping_text(flag):
    # 请求链接
    url = css_info()[0]
    print(url)
    # 返回文本
    text2 = post_request(url)
    # 第一种字体格式
    if flag == '2':
        select = parsel.Selector(text2)
        # 找到所有的text标签
        content_list = select.css('text')
        # 存放信息滴字典
        y_text_dict = {}
        for content in content_list:
            # 获取文本
            # print(content.css("text::text").get())
            line_text = content.css("text::text").get()
            # 获取y属性
            # print(content.css("text::attr(y)").get())
            line_y = content.css("text::attr(y)").get()
            # 保存到字典当中（高度y当作建，内容文本当作值）
            y_text_dict[line_y] = line_text
        return y_text_dict
    #  第二种svg格式
    if flag == '1':
        select = parsel.Selector(text2)
        # 找到所有的path标签
        path_list = select.css('path')
        print("第二种svg格式")
        # print(path_list)
        y_list = []
        for path in path_list:
            # 获取高度
            y = path.css("path::attr(d)").get().split(' ')[1]
            y_list.append(y)
        line_text_list = []
        content_list = select.css('textPath')
        for content in content_list:
            # 获取文本
            line_text = content.css("textPath::text").get()
            line_text_list.append(line_text)
        # 存放信息滴字典
        y_text_dict = {}
        for k, v in zip(y_list, line_text_list):
            y_text_dict[k] = v
        return y_text_dict
